package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1047 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String removeDuplicates(String s) {
            Stack<Character> st = new Stack<>();
            for (char ch : s.toCharArray()) {
                if (!st.isEmpty() && st.peek() == ch) st.pop();
                else st.push(ch);
            }

            StringBuilder res = new StringBuilder();
            while (!st.isEmpty()) res.insert(0, st.pop());
            return res.toString();
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.removeDuplicates("abbaca"));
    }

    public static void main(String[] args) throws Exception {
        LC1047 an = new LC1047();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
